
#include "WorkThreadManager.h"

WorkThreadManager *WorkThreadManager::s_Instance = Q_NULLPTR;

WorkThreadManager::~WorkThreadManager()
{
    if (mNetThread)
    {
        mNetThread->requestInterruption();
        mNetThread->quit();
        mNetThread->wait();

        delete mNetThread;
    }

    s_Instance = Q_NULLPTR;
}

void WorkThreadManager::addToNetThread(QObject *obj)
{
    if (!mNetThread)
    {
        mNetThread = new QThread;
    }

    if (mNetThread)
    {
        connect(mNetThread, &QThread::finished, obj, &QObject::deleteLater);
        obj->moveToThread(mNetThread);

        mNetThread->start();
    }
}

/**********************************************/

void WorkThreadManager::init(void)
{

}

WorkThreadManager::WorkThreadManager(QObject *parent) :
    QObject(parent)
{
    mNetThread = Q_NULLPTR;
}

